import { Pipe, PipeTransform } from '@angular/core';
import { Product } from '../shard/product.service';

@Pipe({
  name: 'filter'
})
export class FilterPipe implements PipeTransform {

  transform(list: Product[], filterField: string, keyword: string): any {
    console.log(1);
    if (!filterField || !keyword ){
      return list;
    }
   /*  return list.filter( item => {
     let fiedValue = item[filterField];
     return fiedValue.indexOf(keyword) >= 0;
    }); */
    console.log(1);
    return list.filter((product:Product) => product[filterField].indexOf(keyword)>=0);
  }

}
